]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
screenshot: change API to return the filename used for saving
authorCosimo Cecchi <cosimoc@gnome.org>
Mon, 10 Dec 2012 14:03:49 +0000 (09:03 -0500)
committerCosimo Cecchi <cosimoc@gnome.org>
Thu, 3 Jan 2013 11:56:45 +0000 (12:56 +0100)
Since we also support passing a basename now, clients might be
interested in knowing the path used to save the file.
Add an out argument to the interface for that.

https://bugzilla.gnome.org/show_bug.cgi?id=688004

js/ui/shellDBus.js
src/shell-screenshot.c
src/shell-screenshot.h

index 4364974068748ff7f231db95fb9b19b5e0c95b3a..f2d91a9abd40b8c380fb95fa582ba7feb64f3188 100644 (file)
@@ -27,6 +27,7 @@ const GnomeShellIface = <interface name="org.gnome.Shell">
     <arg type="b" direction="in" name="flash"/>
     <arg type="s" direction="in" name="filename"/>
     <arg type="b" direction="out" name="success"/>
+    <arg type="s" direction="out" name="filename_used"/>
 </method>
 <method name="ScreenshotWindow">
     <arg type="b" direction="in" name="include_frame"/>
@@ -34,12 +35,14 @@ const GnomeShellIface = <interface name="org.gnome.Shell">
     <arg type="b" direction="in" name="flash"/>
     <arg type="s" direction="in" name="filename"/>
     <arg type="b" direction="out" name="success"/>
+    <arg type="s" direction="out" name="filename_used"/>
 </method>
 <method name="Screenshot">
     <arg type="b" direction="in" name="include_cursor"/>
     <arg type="b" direction="in" name="flash"/>
     <arg type="s" direction="in" name="filename"/>
     <arg type="b" direction="out" name="success"/>
+    <arg type="s" direction="out" name="filename_used"/>
 </method>
 <method name="SelectArea">
     <arg type="i" direction="out" name="x"/>
@@ -118,13 +121,13 @@ const GnomeShell = new Lang.Class({
         return [success, returnValue];
     },
 
-    _onScreenshotComplete: function(obj, result, area, flash, invocation) {
+    _onScreenshotComplete: function(obj, result, area, filenameUsed, flash, invocation) {
         if (flash && result) {
             let flashspot = new Flashspot.Flashspot(area);
             flashspot.fire();
         }
 
-        let retval = GLib.Variant.new('(b)', [result]);
+        let retval = GLib.Variant.new('(bs)', [result, filenameUsed]);
         invocation.return_value(retval);
     },
 
index 5c01093319b58114429b10c3b1c1abcbd6d95f65..b05550ecb08d9d96bdf91ca4c8580aaed7d7f745 100644 (file)
@@ -32,6 +32,7 @@ typedef struct _screenshot_data {
   ShellScreenshot  *screenshot;
 
   char *filename;
+  char *filename_used;
 
   cairo_surface_t *image;
   cairo_rectangle_int_t screenshot_area;
@@ -64,18 +65,21 @@ on_screenshot_written (GObject *source,
   if (screenshot_data->callback)
     screenshot_data->callback (screenshot_data->screenshot,
                                g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (result)),
-                               &screenshot_data->screenshot_area);
+                               &screenshot_data->screenshot_area,
+                               screenshot_data->filename_used);
 
   cairo_surface_destroy (screenshot_data->image);
   g_object_unref (screenshot_data->screenshot);
   g_free (screenshot_data->filename);
+  g_free (screenshot_data->filename_used);
   g_free (screenshot_data);
 }
 
 /* called in an I/O thread */
 static GOutputStream *
 get_stream_for_path (const gchar *path,
-                     const gchar *filename)
+                     const gchar *filename,
+                     gchar **filename_used)
 {
   GOutputStream *stream;
   GFile *file;
@@ -95,15 +99,17 @@ get_stream_for_path (const gchar *path,
 
   file = g_file_new_for_path (real_path);
   stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL));
-  g_free (real_path);
   g_object_unref (file);
 
+  *filename_used = real_path;
+
   return stream;
 }
 
 /* called in an I/O thread */
 static GOutputStream *
-get_stream_for_filename (const gchar *filename)
+get_stream_for_filename (const gchar *filename,
+                         gchar **filename_used)
 {
   const gchar *path;
 
@@ -115,11 +121,12 @@ get_stream_for_filename (const gchar *filename)
         return NULL;
     }
 
-  return get_stream_for_path (path, filename);
+  return get_stream_for_path (path, filename, filename_used);
 }
 
 static GOutputStream *
-prepare_write_stream (const gchar *filename)
+prepare_write_stream (const gchar *filename,
+                      gchar **filename_used)
 {
   GOutputStream *stream;
   GFile *file;
@@ -127,12 +134,13 @@ prepare_write_stream (const gchar *filename)
   if (g_path_is_absolute (filename))
     {
       file = g_file_new_for_path (filename);
+      *filename_used = g_strdup (filename);
       stream = G_OUTPUT_STREAM (g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL));
       g_object_unref (file);
     }
   else
     {
-      stream = get_stream_for_filename (filename);
+      stream = get_stream_for_filename (filename, filename_used);
     }
 
   return stream;
@@ -162,7 +170,8 @@ write_screenshot_thread (GSimpleAsyncResult *result,
 
   g_assert (screenshot_data != NULL);
 
-  stream = prepare_write_stream (screenshot_data->filename);
+  stream = prepare_write_stream (screenshot_data->filename,
+                                 &screenshot_data->filename_used);
 
   if (stream == NULL)
     status = CAIRO_STATUS_FILE_NOT_FOUND;
index 26b3667ee004781a3bac1429f97794d142f6a3b9..76925f31c1507619fb715d7dfb9414ab465b6f23 100644 (file)
@@ -26,8 +26,9 @@ GType shell_screenshot_get_type (void) G_GNUC_CONST;
 ShellScreenshot *shell_screenshot_new (void);
 
 typedef void (*ShellScreenshotCallback)  (ShellScreenshot *screenshot,
-                                           gboolean success,
-                                           cairo_rectangle_int_t *screenshot_area);
+                                          gboolean success,
+                                          cairo_rectangle_int_t *screenshot_area,
+                                          const gchar *filename_used);
 
 void    shell_screenshot_screenshot_area      (ShellScreenshot *screenshot,
                                                 int x,